package com.site.config;

import com.site.parser.ParserFactory;
import com.site.parser.impl.JsonParser;
import com.site.parser.impl.XmlParser;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.beans.factory.config.ServiceLocatorFactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;

/**
 * Created by shengquan.wu on 2018/3/30.
 */
@Configuration
@ComponentScan(basePackages = {"com.site"})
public class AppConfig {

    @Bean
    public FactoryBean serviceLocatorFactoryBean(){
        ServiceLocatorFactoryBean factoryBean=new ServiceLocatorFactoryBean();
        factoryBean.setServiceLocatorInterface(ParserFactory.class);
        return factoryBean;
    }

    @Bean(name = "jsonParser")
    @Scope(value = ConfigurableBeanFactory.SCOPE_SINGLETON)
    public JsonParser jsonParser(){
        return new JsonParser();
    }

    @Bean(name = "xmlParser")
    @Scope(value = ConfigurableBeanFactory.SCOPE_SINGLETON)
    public XmlParser xmlParser(){
        return new XmlParser();
    }

}
